package com.smartgame.renderers;

import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.utils.Disposable;
import com.smartgame.controllers.AbstractController;
import com.smartgame.objects.AbstractObject;
import com.smartgame.util.Constants;

public abstract class AbstractRenderer implements Disposable {

	/** camera used for side-scrolling world view */
	protected OrthographicCamera worldCamera;
	/** camera used for GUI view */
	protected OrthographicCamera guiCamera;
	
	protected SpriteBatch batch;
	protected AbstractController controller;

	public AbstractRenderer(AbstractController controller) {
		this.controller = controller;
		init();
	}

	protected void init() {
		worldCamera = new OrthographicCamera(Constants.VIEWPORT_WIDTH,
				Constants.VIEWPORT_HEIGHT);
		worldCamera.position.set(0, 0, 0);
		worldCamera.update();

		guiCamera = new OrthographicCamera(Constants.VIEWPORT_GUI_WIDTH,
				Constants.VIEWPORT_GUI_HEIGHT);
		guiCamera.position.set(0, 0, 0);
		guiCamera.setToOrtho(true);
		guiCamera.update();
		
		batch = new SpriteBatch();
	}

	public void render() {
		updateBatchWithCamera();
		
		batch.begin();
		renderWorld();
		batch.end();
	}

	protected void renderWorld() {
		for (AbstractObject obj : controller.rendererList) {
			obj.render(batch);
		}
	}

	public abstract void resize(int width, int height);
	
	protected abstract void updateBatchWithCamera();

	@Override
	public void dispose() {
		batch.dispose();
	}

}
